﻿(*   Copyright 2011 Alexander Omelchuk
 *
 *   Licensed under the Apache License, Version 2.0 (the "License");
 *   you may not use this file except in compliance with the License.
 *   You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *   Unless required by applicable law or agreed to in writing, software
 *   distributed under the License is distributed on an "AS IS" BASIS,
 *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *   See the License for the specific language governing permissions and
 *   limitations under the License.
 *)

namespace Lisp
open System
open System.Collections.Generic
open Unchecked

type 'a table = IDictionary<string, 'a>

exception EvalException of string
exception FuncException of string

[<AutoOpen>]
module Base =
  let mkTable<'a> () = Dictionary<string, 'a> () :> 'a table

  // <summary>Raises eval error.</summary>
  let inline raiseError msg = raise(EvalException msg)
  // <summary>Raises error message to insert argument into.</summary>
  let inline raiseArgError msg = raise (FuncException msg)

type SExpr = obj

type Cons = 
  val mutable Car : SExpr
  val mutable Cdr : SExpr
  new (car, cdr) = {Car = car; Cdr = cdr}

type Id = struct
  val Name : string
  new (name) = {Name = name}
end